﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using DataModel;
using P_PersonalDetails.Service.MembershipDetails;
namespace P_PersonalDetails.DataModels
{
    public class MembershipDetailsDM:DataModelBase
    {
        MembershipDetailsData MDD;
        public MembershipDetailsDM(MembershipDetailsData MDD)
        {
            this.MDD = MDD;
        }
        public string Year { get { return MDD.Year.ToString(); } }
        public string FullName { get { return MDD.FullName; } }
        public string RenewalDue { get 
        {
            if (MDD.RenewalDue.HasValue)
                return MDD.RenewalDue.Value.ToLongDateString();
            else
                return "";
             } }
        public string Age { get { return MDD.AgeAtStartOfYear.ToString(); } }

        public int? MembershipType
        {
            get { return MDD.MembershipType; }
            set
            {
                if (MDD.MembershipType != value)
                {
                    MDD.MembershipType = value;
                    OnPropertyChanged("MembershipType");
                }
            }
        }

        public bool BCUCardReqd
        {
            get { return MDD.BCUCardReqd.HasValue? MDD.BCUCardReqd.Value:false; }
            set
            {
                if (MDD.BCUCardReqd != value)
                {
                    MDD.BCUCardReqd = value;
                    OnPropertyChanged("BCUCardReqd");
                }
            }
        }
        public string BCUNumber
        {
            get { return MDD.BCUNumber; }
            set
            {
                if (MDD.BCUNumber != value)
                {
                    MDD.BCUNumber = value;
                    OnPropertyChanged("BCUNumber");
                }
            }
        }

        public DateTime? BCURenewalDate
        {
            get { return MDD.BCURenewalDate; }
            set
            {
                if (MDD.BCURenewalDate != value)
                {
                    MDD.BCURenewalDate = value;
                    OnPropertyChanged("BCURenewalDate");
                }
            }
        }

        protected override void ComitNewObject()
        {
            throw new NotImplementedException();
        }
        protected override void PropertyChangedMethod(string PropertyName, object PropertyValue)
        {
            switch (PropertyName)
            {
                case "MembershipType":
                    MDS.UpdateAsync(MDD.MemberID, "MembershipTypeRC", PropertyValue);
                    break;
                case "BCUNumber":
                case "BCUCardReqd":
                case "BCURenewalDate":
                    MDS.UpdateAsync(MDD.MemberID, PropertyName, PropertyValue);
                    break;
                default:
                    break;
            }
        }

        MembershipDetailsServiceClient MDS = ServiceConfig.NewMembershipDetailsClient();
    }
}
